package edu.njfu.networkdemo.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import edu.njfu.networkdemo.R
import edu.njfu.networkdemo.model.Student

class StudentAdapter(val studentList:List<Student>):RecyclerView.Adapter<StudentAdapter.ViewHolder>() {
    inner class ViewHolder(view: View):RecyclerView.ViewHolder(view) {
        val tv_stuno:TextView=view.findViewById(R.id.tv_stuno)
        val tv_stuname=view.findViewById<TextView>(R.id.tv_stuname);

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view =LayoutInflater.from(parent.context).inflate(R.layout.student_item_layout,parent,false)
        return ViewHolder(view)
    }

    override fun getItemCount(): Int {
        return studentList.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val student=studentList[position]
        holder.tv_stuno.text=student.stuNo
        holder.tv_stuname.text=student.stuName
    }
}